package com.liang.reflectdemo2;

import java.lang.reflect.Field;

public class Test {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException, InstantiationException {
        Class aClass = Class.forName("com.liang.reflectdemo2.Student");

        Object o = aClass.newInstance();
        Field name = aClass.getField("name");

        name.set(o,"zhangsan");

        System.out.println(o);

        Field gender = aClass.getDeclaredField("gender");
        gender.setAccessible(true);
        gender.set(o,"男");
        System.out.println(o);

//        method(aClass);

        Field[] f = aClass.getDeclaredFields();
        for (Field field : f) {
            System.out.println(field);
        }
    }

    public static void method(Class aClass) {
        Field[] fields = aClass.getFields();
        for (Field field : fields) {
            System.out.println(field);
        }
    }
}
